var qqmapsdk, app = getApp(), Data = require("../../utils/util.js"), QQMapWX = require("../../../utils/qqmap-wx-jssdk.js");

Page({
    data: {
        activeIndex: 0,
        index: 0,
        currentTab: 0,
        typeval:'start',
        goodlist:[],
        secTimer:null,
        secAllLoad:false,
        secpagesize:10,
        couponlist: [],
        actEndTimeList:[],
        countDownList:[],
        swiperCurrent: 0,
        indicatorDots: !1,
        autoplay: !0,
        interval: 5e3,
        duration: 1e3,
        circular: !0,
        averdr: !1,
        hotels: !1,
        refresh_top: !1,
        scroll_top: !0,
        index_class: !1,
        seller: [],
        page: 1,
        secpage: 1,
        bkname: "最新信息",
        star: [ {
            img: "../image/xing.png"
        }, {
            img: "../image/xing.png"
        }, {
            img: "../image/xing.png"
        }, {
            img: "../image/xing.png"
        }, {
            img: "../image/xing.png"
        } ],
        star1: [ {
            img: "../image/xing.png"
        }, {
            img: "../image/star_none.png"
        }, {
            img: "../image/star_none.png"
        }, {
            img: "../image/star_none.png"
        }, {
            img: "../image/star_none.png"
        } ],
        star2: [ {
            img: "../image/xing.png"
        }, {
            img: "../image/xing.png"
        }, {
            img: "../image/star_none.png"
        }, {
            img: "../image/star_none.png"
        }, {
            img: "../image/star_none.png"
        } ],
        star3: [ {
            img: "../image/xing.png"
        }, {
            img: "../image/xing.png"
        }, {
            img: "../image/xing.png"
        }, {
            img: "../image/star_none.png"
        }, {
            img: "../image/star_none.png"
        } ],
        star4: [ {
            img: "../image/xing.png"
        }, {
            img: "../image/xing.png"
        }, {
            img: "../image/xing.png"
        }, {
            img: "../image/xing.png"
        }, {
            img: "../image/star_none.png"
        } ]
    },
    updateUserInfo: function(t) {
        console.log(t), "getUserInfo:ok" == t.detail.errMsg && (this.setData({
            hydl: !1
        }), this.reload());
    },
    swiperChange: function(t) {
        this.setData({
            swiperCurrent: t.detail.current
        });
    },
    swiperChange1: function(t) {
        this.setData({
            swiperCurrent1: t.detail.current
        });
    },
    secType:function(e){
      let that = this;
      this.setData({
        typeval: e.currentTarget.dataset.type,
        secpage: 1,
        secAllLoad: false,
      })
      app.util.request({
        url: "entry/wxapp/QgGoods",
        cachetime: "0",
        data:{
          status: that.data.typeval,
          type:1,
          page: 1,
          secAllLoad: false
        },
        success: function (t) {
          if (!t.data || t.data.length == 0 || t.data.length < that.data.secpagesize){
            that.setData({secAllLoad: true})
          }
          t.data = that.dealGoods(t.data)
          that.setData({
            goodlist: t.data
          });
          clearTimeout(that.data.secTimer);
          that.countDown(that.data.typeval == 'finish' ? true : false);
        }
      })
    },
    dealGoods(goods){
      let endTimeList = [],that = this;
      goods.map((item) => {
        item.previewImage = '';
        item.previewImage = 'https://xcx.wzgaolaozhuang.com/attachment/' + item.logo;
        if (that.data.typeval == 'standby'){
          endTimeList.push(item.start_time)
        } else {
          endTimeList.push(item.end_time)
        }
        
        return item;
      })
      this.setData({actEndTimeList: endTimeList});
      return goods;
    },
    jumps: function(t) {
        var a = this, e = (t.currentTarget.dataset.name, t.currentTarget.dataset.appid), n = t.currentTarget.dataset.src, i = t.currentTarget.dataset.id, s = t.currentTarget.dataset.sjtype;
        console.log(i, s);
        var o = t.currentTarget.dataset.type;
        if (1 == o) {
            if (console.log(n), "../distribution/jrhhr" == n) return a.redinfo(), !1;
            if ("../store/store" == n) return wx.switchTab({
                url: "../store/store"
            }), !1;
            if ("../fabu/fabu/fabu" == n) return wx.switchTab({
                url: "../fabu/fabu/fabu"
            }), !1;
            if ("../logs/logs" == n) return wx.switchTab({
                url: "../logs/logs"
            }), !1;
            if ("../type/type" == n) return wx.switchTab({
                url: "../type/type"
            }), !1;
            wx.navigateTo({
                url: n,
                success: function(t) {
                    a.setData({
                        averdr: !0
                    });
                },
                fail: function(t) {},
                complete: function(t) {}
            });
        } else 2 == o ? wx.navigateTo({
            url: "../car/car?vr=" + i + "&sjtype=" + s,
            success: function(t) {},
            fail: function(t) {},
            complete: function(t) {}
        }) : 3 == o && wx.navigateToMiniProgram({
            appId: e,
            path: "",
            extraData: {
                foo: "bar"
            },
            success: function(t) {
                a.setData({
                    averdr: !0
                });
            }
        });
    },
    city_select: function(t) {
        wx.navigateTo({
            url: "city",
            success: function(t) {},
            fail: function(t) {},
            complete: function(t) {}
        });
    },
    delete: function(t) {
        this.setData({
            averdr: !0
        });
    },
    changeIndicatorDots: function(t) {
        this.setData({
            indicatorDots: !this.data.indicatorDots
        });
    },
    changeAutoplay: function(t) {
        this.setData({
            autoplay: !this.data.autoplay
        });
    },
    intervalChange: function(t) {
        this.setData({
            interval: t.detail.value
        });
    },
    durationChange: function(t) {
        this.setData({
            duration: t.detail.value
        });
    },
    settled: function(t) {
        wx.navigateTo({
            url: "../settled/settled"
        });
    },
    onLoad: function(t) {
        console.log("onLoad"), console.log(t);
        var a = decodeURIComponent(t.scene);
        if (console.log("scene", a), "undefined" != a) var e = a;
        if (null != t.userid) {
            console.log("转发获取到的userid:", t.userid);
            e = t.userid;
        }
        if(e){
          this.setData({
            fxzuid: e
          });
        }
        var n = this;
        app.util.request({
            url: "entry/wxapp/System",
            cachetime: "0",
            success: function(t) {
                console.log(t), wx.setNavigationBarTitle({
                    title: t.data.pt_name
                }), wx.setStorageSync("color", t.data.color), wx.setNavigationBarColor({
                    frontColor: "#ffffff",
                    backgroundColor: wx.getStorageSync("color")
                }), 1e4 < Number(t.data.total_num) && (t.data.total_num = (Number(t.data.total_num) / 1e4).toFixed(2) + "万"), 
                n.setData({
                    System: t.data
                });
            }
        }), wx.getSystemInfo({
            success: function(t) {
                n.setData({
                    windowHeight: t.windowHeight
                }), console.log(t);
            }
        }), app.util.request({
            url: "entry/wxapp/Url2",
            cachetime: "0",
            success: function(t) {
                wx.setStorageSync("url2", t.data);
            }
        }), app.util.request({
            url: "entry/wxapp/Llz",
            cachetime: "0",
            data: {
                cityname: wx.getStorageSync("city"),
                type: 2
            },
            success: function(t) {
                console.log(t), n.setData({
                    unitid: t.data
                });
            }
        }), app.util.request({
            url: "entry/wxapp/Url",
            cachetime: "0",
            success: function(t) {
                console.log(t), wx.setStorageSync("url", t.data), n.setData({
                    url: t.data
                });
            }
        }), this.reload();
    },
    timeFormat(param) {//小于10的格式化函数
      return param < 10 ? '0' + param : param;
    },
    countDown:function(endType){

      let newTime = Date.parse(new Date()) / 1000;
      let endTimeList = this.data.actEndTimeList;
      let countDownArr = [];
      
      endTimeList.forEach(o => {
        let obj = null;
        if (!endType){
          if(this.data.typeval == 'start'){
            let endTime = Date.parse(o.replace(/-/g, "/")) / 1000;
            // 如果活动未结束，对时间进行处理
            if (endTime - newTime > 0) {
              let time = (endTime - newTime);
              // 获取天、时、分、秒
              let day = parseInt(time / (60 * 60 * 24));
              let hou = parseInt(time % (60 * 60 * 24) / 3600);
              let min = parseInt(time % (60 * 60 * 24) % 3600 / 60);
              let sec = parseInt(time % (60 * 60 * 24) % 3600 % 60);
              obj = {
                isEnd: false,
                day: this.timeFormat(day),
                hou: this.timeFormat(hou),
                min: this.timeFormat(min),
                sec: this.timeFormat(sec)
              }
            } else {//活动已结束，全部设置为'00'
              obj = {
                isEnd: true
                // day: '00',
                // hou: '00',
                // min: '00',
                // sec: '00'
              }
            }
          } else {
            let startTime = Date.parse(o.replace(/-/g, "/")) / 1000;
            // 如果活动未结束，对时间进行处理
            if (startTime - newTime > 0) {
              let time = (startTime - newTime);
              // 获取天、时、分、秒
              let day = parseInt(time / (60 * 60 * 24));
              let hou = parseInt(time % (60 * 60 * 24) / 3600);
              let min = parseInt(time % (60 * 60 * 24) % 3600 / 60);
              let sec = parseInt(time % (60 * 60 * 24) % 3600 % 60);
              obj = {
                isStart: false,
                day: this.timeFormat(day),
                hou: this.timeFormat(hou),
                min: this.timeFormat(min),
                sec: this.timeFormat(sec)
              }
            } else {//活动已结束，全部设置为'00'
              obj = {
                isStart: true
                // day: '00',
                // hou: '00',
                // min: '00',
                // sec: '00'
              }
            }
          }
        } else {
          console.log('no endType')
          obj = {
            isEnd: true
            // day: '00',
            // hou: '00',
            // min: '00',
            // sec: '00'
          }
        }
        
        countDownArr.push(obj);
      })
      // 渲染，然后每隔一秒执行一次倒计时函数
      this.setData({ countDownList: countDownArr })
      if(!endType) {
        this.data.secTimer = setTimeout(this.countDown, 1000);
      }
    },
    reload: function(t) {
        var c = this, i = this.data.fxzuid;
        console.log(i), wx.login({
            success: function(t) {
                var a = t.code;
                wx.setStorageSync("code", a), wx.getSetting({
                    success: function(t) {
                        console.log(t), t.authSetting["scope.userInfo"] ? wx.getUserInfo({
                            success: function(t) {
                                console.log(t), wx.setStorageSync("user_info", t.userInfo);
                                var e = t.userInfo.nickName, n = t.userInfo.avatarUrl;
                                app.util.request({
                                    url: "entry/wxapp/openid",
                                    cachetime: "0",
                                    data: {
                                        code: a
                                    },
                                    success: function(t) {
                                        console.log(t), wx.setStorageSync("key", t.data.session_key), wx.setStorageSync("openid", t.data.openid);
                                        var a = t.data.openid;
                                        app.util.request({
                                            url: "entry/wxapp/Login",
                                            cachetime: "0",
                                            data: {
                                                openid: a,
                                                img: n,
                                                name: e
                                            },
                                            success: function(t) {
                                                console.log(t), c.setData({
                                                    userinfo: t.data
                                                }), wx.setStorageSync("users", t.data), wx.setStorageSync("uniacid", t.data.uniacid), 
                                                null != i && app.util.request({
                                                    url: "entry/wxapp/Binding",
                                                    cachetime: "0",
                                                    data: {
                                                        fx_user: t.data.id,
                                                        user_id: i
                                                    },
                                                    success: function(t) {
                                                        console.log(t);
                                                    }
                                                });
                                            }
                                        });
                                    }
                                });
                            }
                        }) : (console.log("未授权过"), c.setData({
                            hydl: !0
                        }));
                    }
                });
            }
        }), wx.getLocation({
            type: "wgs84",
            success: function(t) {
                wx.setStorageSync("Location", t);
                var a = t.latitude + "," + t.longitude;
                app.util.request({
                    url: "entry/wxapp/map",
                    cachetime: "0",
                    data: {
                        op: a
                    },
                    success: function(i) {
                        app.util.request({
                            url: "entry/wxapp/System",
                            cachetime: "0",
                            success: function(t) {
                              console.log('+++++++++++++++c', t, '+++++++++++++++++++++++++ce')
                                console.log(t), "1" == t.data.dw_more && c.setData({
                                    dwcity: i.data.result.address_component.district
                                }), "2" == t.data.dw_more && c.setData({
                                    dwcity: i.data.result.address_component.city
                                });
                                var a = t.data.gd_key;
                                "" == a && wx.showModal({
                                    title: "配置提示",
                                    content: "请在后台配置高德地图的key",
                                    showCancel: !0,
                                    cancelText: "取消",
                                    confirmText: "确定",
                                    success: function(t) {},
                                    fail: function(t) {},
                                    complete: function(t) {}
                                }), new (require("../amap-wx.js").AMapWX)({
                                    key: a
                                }).getWeather({
                                    success: function(t) {
                                        var a, e, n = t.liveData.city, i = t.liveData.weather, s = t.liveData.reporttime.slice(0, 10), o = (0 == (a = new Date(s)).getDay() && (e = "星期日"), 
                                        1 == a.getDay() && (e = "星期一"), 2 == a.getDay() && (e = "星期二"), 3 == a.getDay() && (e = "星期三"), 
                                        4 == a.getDay() && (e = "星期四"), 5 == a.getDay() && (e = "星期五"), 6 == a.getDay() && (e = "星期六"), 
                                        e), r = t.temperature.data;
                                        c.setData({
                                            area: n,
                                            reporttime: s,
                                            weather: i,
                                            w1: o,
                                            temperature: r
                                        });
                                    },
                                    fail: function(t) {}
                                });
                                var e = [ "最新信息" ];
                                "1" == t.data.is_sjrz && e.push("热门商家"), "1" == t.data.is_pageopen && "1" == t.data.is_hyqx && e.push("黄页114"), 
                                "1" == t.data.is_pcfw && "1" == t.data.is_pcqx && e.push("顺风车"), "1" == t.data.is_hd && "1" == t.data.is_hdqx && e.push("活动报名"), 
                                console.log(e), wx.setStorageSync("System", t.data), 1 == t.data.many_city ? (wx.setStorageSync("city", t.data.cityname), 
                                c.setData({
                                    city: t.data.cityname
                                })) : (console.log(wx.getStorageSync("city_type")), 1 != wx.getStorageSync("city_type") ? (wx.setStorageSync("city", c.data.dwcity), 
                                c.setData({
                                    city: c.data.dwcity
                                })) : (c.setData({
                                    city: wx.getStorageSync("city")
                                }), console.log("choosecity")));
                                var n = wx.getStorageSync("city");
                                console.log(n), app.util.request({
                                    url: "entry/wxapp/SaveHotCity",
                                    cachetime: "0",
                                    data: {
                                        cityname: n,
                                        user_id: wx.getStorageSync("users").id
                                    },
                                    success: function(t) {
                                        console.log(t);
                                    }
                                }), c.setData({
                                    bkarr: e
                                }), c.refresh(), c.seller();
                            }
                        });
                    }
                });
            },
            fail: function(t) {
                app.util.request({
                    url: "entry/wxapp/System",
                    cachetime: "0",
                    success: function(t) {
                        console.log(t);
                        var a = t.data.gd_key;
                        "" == a && wx.showModal({
                            title: "配置提示",
                            content: "请在后台配置高德地图的key",
                            showCancel: !0,
                            cancelText: "取消",
                            confirmText: "确定",
                            success: function(t) {},
                            fail: function(t) {},
                            complete: function(t) {}
                        }), new (require("../amap-wx.js").AMapWX)({
                            key: a
                        }).getWeather({
                            success: function(t) {
                                var a, e, n = t.liveData.city, i = t.liveData.weather, s = t.liveData.reporttime.slice(0, 10), o = (0 == (a = new Date(s)).getDay() && (e = "星期日"), 
                                1 == a.getDay() && (e = "星期一"), 2 == a.getDay() && (e = "星期二"), 3 == a.getDay() && (e = "星期三"), 
                                4 == a.getDay() && (e = "星期四"), 5 == a.getDay() && (e = "星期五"), 6 == a.getDay() && (e = "星期六"), 
                                e), r = t.temperature.data;
                                c.setData({
                                    area: n,
                                    reporttime: s,
                                    weather: i,
                                    w1: o,
                                    temperature: r
                                });
                            },
                            fail: function(t) {}
                        });
                        var e = [ "最新信息" ];
                        "1" == t.data.is_sjrz && e.push("热门商家"), "1" == t.data.is_pageopen && "1" == t.data.is_hyqx && e.push("黄页114"), 
                        "1" == t.data.is_pcfw && "1" == t.data.is_pcqx && e.push("顺风车"), "1" == t.data.is_hd && "1" == t.data.is_hdqx && e.push("活动报名"), 
                        console.log(e), wx.setStorageSync("System", t.data), wx.setStorageSync("city", t.data.cityname), 
                        c.setData({
                            city: t.data.cityname
                        });
                        var n = wx.getStorageSync("city");
                        console.log(n), c.setData({
                            bkarr: e
                        }), c.refresh(), c.seller();
                    }
                });
            }
        }), app.util.request({
            url: "entry/wxapp/Views",
            cachetime: "0",
            success: function(t) {
                console.log(t);
                var a = t.data;
                "" == a ? a = 0 : 1e4 < Number(a) && (a = (Number(a) / 1e4).toFixed(2) + "万"), c.setData({
                    views: a
                });
            }
        }), app.util.request({
            url: "entry/wxapp/Num",
            cachetime: "0",
            success: function(t) {
                c.setData({
                    Num: t.data
                });
            }
          }), app.util.request({
            url: "entry/wxapp/QgGoods",
            cachetime: "0",
            data: {
              page: 1,
              type:1,
              status: c.data.typeval
            },
            success: function (t) {
              if (!t.data || t.data.length == 0 || t.data.length < c.data.secpagesize) {
                c.setData({ secAllLoad: true })
              }
              // 获取商品列表
              t.data = c.dealGoods(t.data);
              c.setData({
                goodlist: t.data
              });
              clearTimeout(c.data.secTimer);
              c.countDown(c.data.typeval == 'finish' ? true : false);
            }
          }), c.getCoupon();
    },
    refresh: function(t) {
        var o = this, a = wx.getStorageSync("city");
        app.util.request({
            url: "entry/wxapp/RmStore",
            cachetime: "0",
            data: {
                cityname: a
            },
            success: function(t) {
                t.data.length <= 5 ? o.setData({
                    store: t.data
                }) : o.setData({
                    store: t.data.slice(0, 6)
                });
            }
        }), app.util.request({
            url: "entry/wxapp/Ad",
            cachetime: "0",
            data: {
                cityname: a
            },
            success: function(t) {
                console.log(t);
                var a = [], e = [], n = [], i = [];
                for (var s in t.data) 1 == t.data[s].type && a.push(t.data[s]), 5 == t.data[s].type && e.push(t.data[s]), 
                7 == t.data[s].type && n.push(t.data[s]), 10 == t.data[s].type && i.push(t.data[s]);
                o.setData({
                    slide: a,
                    advert: e,
                    ggslide: n,
                    zjggbk: i
                });
            }
        }), app.util.request({
            url: "entry/wxapp/news",
            cachetime: "0",
            data: {
                cityname: a
            },
            success: function(t) {
                var a = [];
                for (var e in t.data) 1 == t.data[e].type && a.push(t.data[e]);
                o.setData({
                    msgList: a
                });
            }
        }), app.util.request({
            url: "entry/wxapp/GetNav",
            cachetime: "0",
            success: function(t) {
                console.log(t);
                var a = t.data;
                a.length <= 5 ? o.setData({
                    height: 150
                }) : 5 < a.length && o.setData({
                    height: 300
                });
                for (var e = [], n = 0, i = a.length; n < i; n += 10) e.push(a.slice(n, n + 10));
                o.setData({
                    nav: e,
                    navs: a
                });
            }
        });
    },
    getCoupon:function(){
      var a = this,s=[];
      app.util.request({
        url: "entry/wxapp/indexcoupon",
        cachetime: "0",
        data: {},
        success: function (t) {
          console.log(t.data);
          for (var e = 0; e < t.data.length; e++) {
            t.data[e].rate = parseInt(100 * (1 - Number(t.data[e].surplus) / Number(t.data[e].number)));
          }
          s = s.concat(t.data), s = function (t) {
            for (var e = [], a = 0; a < t.length; a++) -1 == e.indexOf(t[a]) && e.push(t[a]);
            return e;
          }(s), console.log(s), a.setData({
            couponlist: s
          });
        }
      });
    },
    sjbk: function() {
        var m = this, t = wx.getStorageSync("city");
        console.log("城市为" + t), console.log("page数量为" + m.data.page);
        var y = m.data.page, w = m.data.store1;
        app.util.request({
            url: "entry/wxapp/StoreList",
            cachetime: "0",
            data: {
                page: y,
                cityname: t
            },
            success: function(t) {
                if (console.log(t), 0 == t.data.length ? m.setData({
                    refresh_top: !0
                }) : (m.setData({
                    refresh_top: !1,
                    page: y + 1,
                    issljz: !0
                }), w = w.concat(t.data)), 0 < t.data.length) {
                    for (var a = {}, e = [], n = 0, i = w.length; n < i; n++) a[w[n]] || (e.push(w[n]), 
                    a[w[n]] = !0);
                    for (var s in t.data) {
                        t.data[s].star = m.data.star1;
                        t.data[s].star;
                        t.data[s].score = Number(t.data[s].score);
                        t.data[s].score;
                        var o = t.data[s].coordinates.split(",");
                        t.data[s].lat2 = Number(wx.getStorageSync("Location").latitude), t.data[s].lng2 = Number(wx.getStorageSync("Location").longitude);
                        var r = Number(wx.getStorageSync("Location").latitude), c = Number(wx.getStorageSync("Location").longitude), l = o[0], u = o[1], d = r * Math.PI / 180, g = l * Math.PI / 180, p = d - g, f = c * Math.PI / 180 - u * Math.PI / 180, h = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(p / 2), 2) + Math.cos(d) * Math.cos(g) * Math.pow(Math.sin(f / 2), 2)));
                        h *= 6378.137;
                        h = (h = Math.round(1e4 * h) / 1e4).toFixed(2);
                        t.data[s].distance = h;
                    }
                    m.setData({
                        store1: w.sort(function(t, a) {
                            return (t = Number(t.distance)) < (a = Number(a.distance)) ? -1 : a < t ? 1 : 0;
                        })
                    });
                } else m.setData({
                    store1: w
                });
            }
        });
    },
    seller: function(t) {
        var o = this, a = (o.data.index_class, wx.getStorageSync("city")), r = (wx.getStorageSync("index"), 
        o.data.page), c = o.data.seller;
        console.log(a, r), app.util.request({
            url: "entry/wxapp/list2",
            cachetime: "0",
            data: {
                page: o.data.page,
                cityname: a
            },
            success: function(t) {
                if (console.log(t.data), 0 == t.data.length) o.setData({
                    refresh_top: !0
                }); else {
                    o.setData({
                        refresh_top: !1,
                        page: r + 1,
                        issljz: !0
                    }), c = c.concat(t.data), c = function(t) {
                        for (var a = [], e = 0; e < t.length; e++) -1 == a.indexOf(t[e]) && a.push(t[e]);
                        return a;
                    }(c);
                }
                if (0 < t.data.length) {
                    for (var a in t.data) {
                        var e = app.ormatDate(t.data[a].tz.sh_time);
                        t.data[a].tz.img = t.data[a].tz.img.split(","), t.data[a].tz.details = t.data[a].tz.details.replace("↵", " "), 
                        4 < t.data[a].tz.img.length && (t.data[a].tz.img_length = Number(t.data[a].tz.img.length) - 4), 
                        4 <= t.data[a].tz.img.length ? t.data[a].tz.img1 = t.data[a].tz.img.slice(0, 4) : t.data[a].tz.img1 = t.data[a].tz.img, 
                        t.data[a].tz.time = e.slice(0, 16);
                    }
                    for (var n in c) {
                        for (var i in c[n].label) c[n].label[i].number = (void 0, s = "rgb(" + Math.floor(255 * Math.random()) + "," + Math.floor(255 * Math.random()) + "," + Math.floor(255 * Math.random()) + ")", 
                        s);
                        o.setData({
                            seller: c
                        });
                    }
                } else o.setData({
                    seller: c
                });
                var s;
            }
        });
    },
    hybk: function() {
        var g = this, t = (g.data.index_class, wx.getStorageSync("city")), p = (wx.getStorageSync("index"), 
        g.data.page), f = g.data.yellow_list;
        console.log(t), app.util.request({
            url: "entry/wxapp/YellowPageList",
            cachetime: "0",
            data: {
                page: p,
                cityname: t
            },
            success: function(t) {
                if (console.log(t), 0 == t.data.length ? g.setData({
                    refresh_top: !0
                }) : (g.setData({
                    refresh_top: !1,
                    page: p + 1,
                    issljz: !0
                }), f = f.concat(t.data)), 0 < t.data.length) {
                    for (var a in f) {
                        var e = f[a].coordinates.split(",");
                        f[a].lat2 = Number(wx.getStorageSync("Location").latitude), f[a].lng2 = Number(wx.getStorageSync("Location").longitude);
                        var n = Number(wx.getStorageSync("Location").latitude), i = Number(wx.getStorageSync("Location").longitude), s = e[0], o = e[1], r = n * Math.PI / 180, c = s * Math.PI / 180, l = r - c, u = i * Math.PI / 180 - o * Math.PI / 180, d = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(l / 2), 2) + Math.cos(r) * Math.cos(c) * Math.pow(Math.sin(u / 2), 2)));
                        d *= 6378.137;
                        d = (d = Math.round(1e4 * d) / 1e4).toFixed(2);
                        f[a].distance = d;
                    }
                    g.setData({
                        yellow_list: f.sort(function(t, a) {
                            return (t = Number(t.distance)) < (a = Number(a.distance)) ? -1 : a < t ? 1 : 0;
                        })
                    });
                } else g.setData({
                    yellow_list: f
                });
            }
        });
    },
    sfcbk: function() {
        var e = this, t = (e.data.index_class, wx.getStorageSync("city")), n = (wx.getStorageSync("index"), 
        e.data.page), i = e.data.pc;
        console.log(t), app.util.request({
            url: "entry/wxapp/CarList",
            cachetime: "0",
            data: {
                page: n,
                cityname: t
            },
            success: function(t) {
                if (console.log(t), 0 == t.data.length ? e.setData({
                    refresh_top: !0
                }) : (e.setData({
                    refresh_top: !1,
                    page: n + 1,
                    issljz: !0
                }), i = i.concat(t.data)), 0 < t.data.length) {
                    for (var a in t.data) t.data[a].tz.time = app.ormatDate(t.data[a].tz.time).slice(5, 16), 
                    t.data[a].tz.start_time1 = t.data[a].tz.start_time.slice(5, 10), t.data[a].tz.start_time2 = t.data[a].tz.start_time.slice(10, 17), 
                    2 == t.data[a].tz.is_open ? (t.data[a].tz.class2 = "car3", t.data[a].tz.class3 = "car4", 
                    t.data[a].tz.class4 = "car5") : (t.data[a].tz.class2 = "", t.data[a].tz.class3 = "", 
                    t.data[a].tz.class4 = ""), "人找车" == t.data[a].tz.typename ? (t.data[a].tz.class = "color1", 
                    t.data[a].tz.class1 = "car1") : "车找人" == t.data[a].tz.typename ? (t.data[a].tz.class = "color2", 
                    t.data[a].tz.class1 = "car2") : "货找车" == t.data[a].tz.typename ? (t.data[a].tz.class = "color1", 
                    t.data[a].tz.class1 = "car1") : "车找货" == t.data[a].tz.typename && (t.data[a].tz.class = "color2", 
                    t.data[a].tz.class1 = "car2");
                    e.setData({
                        pc: i
                    });
                } else e.setData({
                    pc: i
                });
            }
        });
    },
    hdbmbk: function(t) {
        var e = this, a = Data.formatTime(new Date()), n = Data.formatTime(new Date()).replace(/\//g, "-").toString();
        console.log(a, n);
        var i = wx.getStorageSync("city"), s = e.data.page, o = e.data.hdlist;
        console.log(i), app.util.request({
            url: "entry/wxapp/Activity",
            cachetime: "0",
            data: {
                type_id: "",
                page: s,
                pagesize: 10,
                cityname: i
            },
            success: function(t) {
                console.log(t.data), 0 == t.data.length ? e.setData({
                    refresh_top: !0
                }) : e.setData({
                    refresh_top: !1,
                    page: s + 1,
                    issljz: !0
                }), o = function(t) {
                    for (var a = [], e = 0; e < t.length; e++) -1 == a.indexOf(t[e]) && a.push(t[e]);
                    return a;
                }(o = o.concat(t.data)), console.log(o);
                for (var a = 0; a < o.length; a++) o[a].end_time > n ? o[a].isgq = 2 : o[a].isgq = 1;
                e.setData({
                    hdlist: o
                });
            }
        });
    },
    bkswiperChange: function(t) {
        var a = this;
        console.log("===== swiperChange " + t.detail.current), a.setData({
            refresh_top: !1,
            activeIndex: t.detail.current
        });
        var e = a.data.bkarr[t.detail.current];
        console.log(e), "最新信息" == e && a.seller(), "热门商家" == e && a.sjbk(), "黄页114" == e && a.hybk(), 
        "顺风车" == e && a.sfcbk();
    },
    commend: function(t) {
        var a = this;
        t.currentTarget.dataset.index;
        var e = t.currentTarget.id, n = t.currentTarget.dataset.name;
        wx.setStorageSync("index", e), console.log(n), a.setData({
            index_class: !0,
            activeIndex: t.currentTarget.dataset.index,
            toView: "a" + (t.currentTarget.dataset.index - 1),
            bkname: n,
            refresh_top: !1,
            swipecurrent: t.currentTarget.id,
            seller: [],
            store1: [],
            yellow_list: [],
            pc: [],
            hdlist: [],
            page: 1,
            issljz: !1
        }), "最新信息" == n && a.seller(), "热门商家" == n && a.sjbk(), "黄页114" == n && a.hybk(), 
        "顺风车" == n && a.sfcbk(), "活动报名" == n && a.hdbmbk();
    },
    whole: function(t) {
        wx.removeStorage({
            key: "index",
            success: function(t) {}
        }), this.setData({
            page: 1,
            seller: [],
            index_class: !1
        }), this.seller();
    },
    bindinput: function(t) {
        var a = t.detail.value;
        "" != a && app.util.request({
            url: "entry/wxapp/list2",
            cachetime: "0",
            data: {
                keywords: a
            },
            success: function(t) {
                0 == t.data.length ? wx.showModal({
                    title: "提示",
                    content: "没有这个帖子",
                    showCancel: !0,
                    cancelText: "取消",
                    confirmText: "确定",
                    success: function(t) {},
                    fail: function(t) {},
                    complete: function(t) {}
                }) : wx.navigateTo({
                    url: "../infodetial/infodetial?id=" + t.data[0].tz.id,
                    success: function(t) {},
                    fail: function(t) {},
                    complete: function(t) {}
                });
            }
        });
    },
    ormatDate: function(t) {
        var a = new Date(1e3 * t);
        return a.getFullYear() + "-" + e(a.getMonth() + 1, 2) + "-" + e(a.getDate(), 2) + " " + e(a.getHours(), 2) + ":" + e(a.getMinutes(), 2) + ":" + e(a.getSeconds(), 2);
        function e(t, a) {
            for (var e = "" + t, n = e.length, i = "", s = a; s-- > n; ) i += "0";
            return i + e;
        }
    },
    thumbs_up: function(t) {
        var e = this, n = e.data.seller, i = t.currentTarget.dataset.id, s = wx.getStorageSync("users").id, a = (Number(t.currentTarget.dataset.num), 
        function(a) {
            n[a].tz.id == i && (n[a].thumbs_up = !0, app.util.request({
                url: "entry/wxapp/Like",
                cachetime: "0",
                data: {
                    information_id: i,
                    user_id: s
                },
                success: function(t) {
                    1 != t.data ? wx.showModal({
                        title: "提示",
                        content: "不能重复点赞",
                        showCancel: !0,
                        cancelText: "取消",
                        confirmText: "确认",
                        success: function(t) {},
                        fail: function(t) {},
                        complete: function(t) {}
                    }) : (n[a].tz.givelike = Number(n[a].tz.givelike) + 1, e.setData({
                        seller: n
                    }));
                }
            }));
        });
        for (var o in n) a(o);
    },
    previewImage: function(t) {
        console.log(t);
        var a = t.currentTarget.dataset.id, e = this.data.url, n = [], i = t.currentTarget.dataset.inde, s = this.data.seller;
        for (var o in s) if (s[o].tz.id == a) {
            var r = s[o].tz.img;
            for (var c in r) n.push(e + r[c]);
            wx.previewImage({
                current: e + r[i],
                urls: n
            });
        }
    },
    red: function(t) {
        wx.navigateTo({
            url: "../redbag/redbag",
            success: function(t) {},
            fail: function(t) {},
            complete: function(t) {}
        });
    },
    redinfo: function(t) {
        var a = wx.getStorageSync("users").id;
        app.util.request({
            url: "entry/wxapp/MyDistribution",
            cachetime: "0",
            data: {
                user_id: a
            },
            success: function(t) {
                console.log(t.data), "2" == t.data.state ? (console.log("是分销商"), wx.navigateTo({
                    url: "../distribution/yaoqing"
                })) : "1" == t.data.state ? wx.showModal({
                    title: "提示",
                    content: "您的申请正在审核中，请耐心等待"
                }) : wx.navigateTo({
                    url: "../distribution/jrhhr"
                });
            }
        });
    },
    yellow_page: function(t) {
        wx.reLaunch({
            url: "../yellow_page/yellow"
        });
    },
    post1: function(t) {
        wx.switchTab({
            url: "../fabu/fabu/fabu"
        });
    },
    store_info: function(t) {
        var a = t.currentTarget.id;
        wx.navigateTo({
            url: "../sellerinfo/sellerinfo?id=" + a,
            success: function(t) {},
            fail: function(t) {},
            complete: function(t) {}
        });
    },
    notice: function(t) {
        var a = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "../notice/notice?id=" + a,
            success: function(t) {},
            fail: function(t) {},
            complete: function(t) {}
        });
    },
    post: function(t) {
        wx, wx.reLaunch({
            url: "../shun/shun",
            success: function(t) {},
            fail: function(t) {},
            complete: function(t) {}
        });
    },
    phone: function(t) {
        var a = t.currentTarget.dataset.id;
        wx.makePhoneCall({
            phoneNumber: a
        });
    },
    more: function(t) {
        console.log(t), wx.switchTab({
            url: "../store/store"
        });
    },
    moreCoupon: function(t){
      wx.navigateTo({
        url: "../wdq/yhqlist"
      });
    },
    jump: function(t) {
        var a = t.currentTarget.dataset.id, e = t.currentTarget.dataset.name;
        wx.navigateTo({
            url: "../marry/marry?id=" + a + "&name=" + e,
            success: function(t) {},
            fail: function(t) {},
            complete: function(t) {}
        });
    },
    carinfo: function(t) {
        console.log(t);
        var a = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "../shun/shuninfo2/shuninfo2?id=" + a,
            success: function(t) {},
            fail: function(t) {},
            complete: function(t) {}
        });
    },
    yellow_info: function(t) {
        var a = t.currentTarget.dataset.id, e = t.currentTarget.dataset.user_id;
        console.log(e), wx.navigateTo({
            url: "../yellow_page/yellowinfo?id=" + a,
            success: function(t) {},
            fail: function(t) {},
            complete: function(t) {}
        });
    },
    store: function(t) {
        var a = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "../sellerinfo/sellerinfo?id=" + a,
            success: function(t) {},
            fail: function(t) {},
            complete: function(t) {}
        });
    },
    see: function(t) {
        this.data.seller;
        var a = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "../infodetial/infodetial?id=" + a,
            success: function(t) {},
            fail: function(t) {},
            complete: function(t) {}
        });
    },
    formid_one: function(t) {
        console.log("搜集第一个formid"), console.log(t), app.util.request({
            url: "entry/wxapp/SaveFormid",
            cachetime: "0",
            data: {
                user_id: wx.getStorageSync("users").id,
                form_id: t.detail.formId,
                openid: wx.getStorageSync("openid")
            },
            success: function(t) {}
        });
    },
    hddb: function() {
        wx.pageScrollTo({
            scrollTop: 0,
            duration: 300
        });
    },
    onReady: function() {
        this.setData({
            first: 1
        }), wx.removeStorageSync("city_type");
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {
        wx.removeStorageSync("city_type");
    },
    onPullDownRefresh: function() {
        this.setData({
            page: 1,
            secpage: 1,
            secAllLoad: false,
            seller: [],
            activeIndex: 0,
            swipecurrent: 0,
            refresh_top: !1
        }), this.reload(), wx.stopPullDownRefresh();
    },
    onReachBottom: function() {
        var t = this, a = this.data.bkname;
        0 == this.data.refresh_top && this.data.issljz ? (console.log("上拉触底", a), "最新信息" == a && t.seller(), 
        "热门商家" == a && t.sjbk(), "黄页114" == a && t.hybk(), "顺风车" == a && t.sfcbk(), "活动报名" == a && t.hdbmbk()) : console.log("dobutno");

      if (t.data.secAllLoad == false){
        app.util.request({
          url: "entry/wxapp/QgGoods",
          cachetime: "0",
          data: {
            type:1,
            status: t.data.typeval,
            page: t.data.secpage + 1
          },
          success: function (res) {
            if (!res.data || res.data.length == 0 || res.data.length < t.data.secpagesize) {
              t.setData({ secAllLoad: true })
            }
            res.data = t.dealGoods(t.data.goodlist.concat(res.data));
            t.setData({
              goodlist: res.data,
              page: t.data.secpage + 1
            });
            clearTimeout(t.data.secTimer);
            t.countDown(t.data.typeval == 'finish' ? true : false);
          }
        })
      }
      
    },
    onShareAppMessage: function() {
        var t = this.data.System.zf_title;
        return "" == t && (t = this.data.System.pt_name), console.log(t), {
            title: t,
            path: "/zh_tcwq/pages/index/index",
            success: function(t) {},
            fail: function(t) {}
        };
    }
});